package data;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class TimeUnit {

	private int _id;
//	private Calendar _startTime;
//	private Calendar _endTime;
	private int _timesize;
	private long _totalKbWritten;
	private long _totalKbRead;
	private int _numReads;
	private int _numWrites;
	private Calendar start;


//	public TimeUnit(int id, Calendar stime, Calendar etime, long kbWritten, long kbRead,
//			int numReads, int numWrites) {
//		_id = id;
//		_startTime = stime;
//		_endTime = etime;
//		_totalKbWritten = kbWritten;
//		_totalKbRead = kbRead;
//		_numReads=numReads;
//		_numWrites=numWrites;
//	}
	public TimeUnit(int id, int time, long kbWritten, long kbRead,
			int numReads, int numWrites) {
		_id = id;
		_timesize = time;
		_totalKbWritten = kbWritten;
		_totalKbRead = kbRead;
		_numReads=numReads;
		_numWrites=numWrites;
		start = GregorianCalendar.getInstance();
	}


//	public TimeUnit(int id, Calendar stime, Calendar etime) {
//		_id = id;
//		_startTime = stime;
//		_endTime = etime;
//		_totalKbWritten = 0;
//		_totalKbRead = 0;
//		_numReads=0;
//		_numWrites=0;
//	}

	public TimeUnit(int id, int time) {
		_id = id;
		_timesize = time;
		_totalKbWritten = 0;
		_totalKbRead = 0;
		_numReads=0;
		_numWrites=0;
		start = GregorianCalendar.getInstance();
	}


	public TimeUnit(int id, int size, Calendar d) {
		_id = id;
		_timesize = size;
		_totalKbWritten = 0;
		_totalKbRead = 0;
		_numReads=0;
		_numWrites=0;
		start = d;
	}


	public Calendar getStart() {
		return start;
	}


	public int get_id() {
		return _id;
	}


//	public Calendar get_startTime() {
//		return _startTime;
//	}
//
//
//	public Calendar get_endTime() {
//		return _endTime;
//	}


	public long get_totalKbWritten() {
		return _totalKbWritten;
	}


	public long get_totalKbRead() {
		return _totalKbRead;
	}


	public int get_numReads() {
		return _numReads;
	}


	public int get_numWrites() {
		return _numWrites;
	}

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TimeUnit other = (TimeUnit) obj;
        if (this._id != other._id) {
            return false;
        }
//        if (this._startTime != other._startTime && (this._startTime == null || !this._startTime.equals(other._startTime))) {
//            return false;
//        }
//        if (this._endTime != other._endTime && (this._endTime == null || !this._endTime.equals(other._endTime))) {
//            return false;
//        }
        if(this._timesize != other._timesize){
        	return false;
        }

        if (this._totalKbWritten != other._totalKbWritten) {
            return false;
        }
        if (this._totalKbRead != other._totalKbRead) {
            return false;
        }
        if (this._numReads != other._numReads) {
            return false;
        }
        if (this._numWrites != other._numWrites) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + this._id;
//        hash = 23 * hash + (this._startTime != null ? this._startTime.hashCode() : 0);
//        hash = 23 * hash + (this._endTime != null ? this._endTime.hashCode() : 0);
        hash = 23 * hash + (int) (this._totalKbWritten ^ (this._totalKbWritten >>> 32));
        hash = 23 * hash + (int) (this._totalKbRead ^ (this._totalKbRead >>> 32));
        hash = 23 * hash + this._numReads;
        hash = 23 * hash + this._numWrites;
        return hash;
    }

    @Override
    public String toString() {
//        return "id: "+_id+" startTime: "+_startTime.getTimeInMillis()+" endTime: "+_endTime.getTimeInMillis()+" kbWritten: "+_totalKbWritten+ " kbRead: "+_totalKbRead+" numOfReads "+_numReads+" numOfWrites "+_numWrites;
        return "id: "+_id+" startTime: "+_timesize+" kbWritten: "+_totalKbWritten+ " kbRead: "+_totalKbRead+" numOfReads "+_numReads+" numOfWrites "+_numWrites;
    }


	public void updateWithLPTU(LUNPerTimeUnit lptu) {
		_numReads+= lptu.get_numOfReads();
		_numWrites+= lptu.get_numOfWrites();
		_totalKbRead+= lptu.get_totalKbRead();
		_totalKbWritten+= lptu.get_totalKbWritten();
	}


	public int get_timesize() {
		return _timesize;
	}
}

